<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\helpers\Url;
use yii\widgets\LinkPager;
$this->title = '系统日志';
?>
<?= Html::cssFile('./assets/date/bootstrap-datetimepicker.min.css')?>
<style>

	.form-group{margin-bottom: -21px; display: inline-block;}
</style>
<div class="container">
    <div class="row">
      
        <?php echo $this->render('_leftnav') ?>

        <div class="col-md-10">
          <div class="page-header clearfix">
            <h1 class="pull-left">系统操作日志</h1>
            <div class="pull-right">

                                            
            </div>
          </div>

<!--站点配置表单类-->
<?php
$form = ActiveForm::begin([
    'action'=>"",
    'method'=>'post',
	'fieldConfig' => [
		'template' => '{input}{error}'
	],
]);
?>
	<div class="form-group">
	  <?= $form->field($admin, 'log_type')->dropDownList(['1'=>'删除','2'=>'增加','3'=>'修改'], ['prompt'=>'--所有等级--','class'=>'form-control','id'=>'log_type']) ?>
	</div>
<!--    <select class="form-control" name="level">-->
<!--        <option selected="selected" value="">--所有等级--</option><option value="info">提示</option><option value="warning">警告</option><option value="error">错误</option>-->
<!--    </select>-->


  <div class="form-group">
	  <?= $form->field($admin, 'startDateTime',['inputOptions'=>['placeholder'=>'起始时间']])->textInput(['id' => 'startDateTime','class' => 'form-control form_datetime','style' => 'width:120px;']) ?>
	  <!--    <input id="startDateTime" name="startDateTime" class="form-control form_datetime" placeholder="起始时间" style="width:150px;" type="text">-->
  </div>

  <div class="form-group">
	  <?= $form->field($admin, 'endDateTime',['inputOptions'=>['placeholder'=>'结束时间']])->textInput(['id' => 'endDateTime','class' => 'form-control form_datetime','style' => 'width:120px;']) ?>
<!--    <input id="endDateTime" name="endDateTime" class="form-control form_datetime" placeholder="结束时间" style="width:150px;" type="text">-->
  </div>

  <div class="form-group">
	  <?= $form->field($admin, 'log_info',['inputOptions'=>['placeholder'=>'操作名']])->textInput(['class' => 'form-control','style' => 'width:100px;','id'=>'log_info']) ?>
<!--    <input id="action" name="action" class="form-control" placeholder="操作名" style="width:100px;" type="text">-->
  </div>

  <div class="form-group">
	  <?= $form->field($admin, 'user_name',['inputOptions'=>['placeholder'=>'用户名']])->textInput(['class' => 'form-control','style' => 'width:120px;','id'=>'user_name']) ?>
<!--    <input id="nickname" name="nickname" class="form-control" placeholder="用户名" style="width:120px;" type="text">-->
  </div>
	<div class="form-group">
<!--  <button class="btn btn-primary">搜索</button>-->
	<?= Html::Button('搜索', ['class'=>'btn btn-primary']) ?>
	</div>

<?php ActiveForm::end();?>

<div id="user_message" class="modal fade"></div>

<table class="table table-hover" id="log-table" style="margin-top: 25px;">
    <tbody>
	    <tr>
	      <th width="15%">用户</th>
	      <th width="55%">操作</th>
	      <th width="10%">日志等级</th>
	      <th width="20%">时间/IP</th>
	    </tr>
	    <?php foreach($model as $k=>$v){?>
        <tr>
            <td>
                <a href="javascript:;" role="show-user" data-toggle="modal" data-target="#user_message" val="<?= Html::encode($v['admin_id']);?>" id="message"><?= Html::encode($v['user_name']);?></a>
	
            </td>
	        <td>
                <div style="word-break: break-all;word-wrap: break-word;">
	                <?= Html::encode($v['log_info']);?>
                </div>
            </td>
            <td>
	            <span>
		            <?php if(Html::encode($v['log_type']) == "1"){?>
		                删除
		            <?php }elseif(Html::encode($v['log_type']) == "2"){?>
		                增加
		            <?php }else{ ?>
			            修改
		            <?php } ?>
	            </span>
            </td>
	        <td>
	            <span class=""><?= Html::encode(date("Y-m-d H:i:s",$v['log_addtime']));?></span>
	        </td>
        </tr>
    <?php } ?>
	</tbody>
</table>
	        <center id="page">
	        <?php echo LinkPager::widget([
		        'pagination' => $pagination,
		        'firstPageLabel'=>"首页",
		        'prevPageLabel'=>'上一页',
		        'nextPageLabel'=>'下一页',
		        'lastPageLabel'=>'尾页',
	        ]);?>
	        </center>
        </div>
    </div>
</div>
<?= Html::jsFile('./assets/date/bootstrap-datetimepicker.min.js')?>
<?= Html::jsFile('./assets/date/bootstrap-datetimepicker.fr.js')?>
<script>
	/*用户信息*/
	$(document).on('click',"#message",function(){
		var admin_id = $(this).attr("val");
		$.ajax({
			type: "POST",
			url: "<?= Url::to(['system/usermessage']);?>",
			data: "admin_id="+admin_id,
			success: function(msg){
				$("#user_message").html(msg)
			}
		});
	})
	/*ajax分页*/
	$(document).on('click','.pagination a,.btn-primary',function(link){
		var page = parseInt($(this).attr("data-page"))+1;
		var log_type = $("#log_type").val();
		var startDateTime = $("#startDateTime").val();
		var endDateTime = $("#endDateTime").val();
		var log_info = $("#log_info").val();
		var user_name = $("#user_name").val();
		$.ajax({
			type: "GET",
			url: "<?= Url::to(['system/logspage']);?>",
			dataType:"json",
			data: "page="+page+"&log_type="+log_type+"&startDateTime="+startDateTime+"&endDateTime="+endDateTime+"&log_info="+log_info+"&user_name="+user_name,
			success: function(msg) {
				if (msg == "1") {
					alert("对不起，无数据");
				}
				else {
					var list = '<tbody><tr><th width="15%">用户</th><th width="55%">操作</th><th width="10%">日志等级</th><th width="20%">时间/IP</th></tr>';
					for (var i = 0; i < msg['model'].length; i++) {
						list += "<tr>" + "<td>" + "<a href='javascript:;' role='show-user' data-toggle='modal' data-target='#user_message' id='message' val='" + msg['model'][i].admin_id + "'>" + msg['model'][i].user_name + "</a></td><td>" + "<div style='word-break: break-all;word-wrap: break-word;'>" + msg['model'][i].log_info + "</div></td><td><span>";
						if (msg['model'][i]['log_type'] == "1") {
							list += "删除";
						} else if (msg['model'][i]['log_type'] == "2") {
							list += "增加";
						}
						else {
							list += "修改";
						}
						list += "</span></td><td><span class=''>" + msg['model'][i].log_addtime + "</span></td></tr>";
					}
					list += '</tbody>';
					$("#log-table").html(list)
					$("#page").html(msg['pagination']);
				}
			}
		});
		return false;
	})
	$(".form_datetime").datetimepicker({
		autoclose: 1,
		todayHighlight: 1,
		startView:2
	});
</script>